package com.ts.api.http.feedback;

import com.gitee.apanlh.web.model.vo.RequestVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Optional;

/**
 * 回传
 *
 * @author caoxin
 */
@Component
public class Feedback {

    @Autowired(required = false)
    private List<FeedbackHandler> feedbackHandlerList = java.util.Collections.emptyList();

    public Object feedback(RequestVO requestVO) {
        // 查找匹配的回传处理器
        Optional<FeedbackHandler> feedbackHandlerOptional = this.feedbackHandlerList.stream()
                .filter(feedbackHandler -> {
                    return feedbackHandler.match(requestVO);
                }).findFirst();
        // 回传
        if(feedbackHandlerOptional.isPresent()) {
            return feedbackHandlerOptional.get().feedback(requestVO);
        }
        return new HashMap<>();
    }
}
